print("Example script dz_cisha.lua.")
local scheme = ut.newSpellQueue()

function getComboPoints()
    return UnitPower('player', 4)
end

function MaxComboPoints()
    return UnitPowerMax('player', 4)
end

function getEnergy()
    return UnitPower('player', 3)
end

function MaxEnergy()
    return UnitPowerMax('player', 3)
end

scheme.add('割裂', 'target', function()
    return getDebuffRemainTime( 'target', '割裂' ) <= 8 and getComboPoints() == MaxComboPoints()
end)
scheme.add('猩红之瓶', 'player', function()
    return getHpParent('player') < 0.8
end)

scheme.add('锁喉', 'target', function()
    return getDebuffRemainTime( 'target', '锁喉' ) < 5 
end)

scheme.add('出血', 'target', function()
    return getDebuffRemainTime( 'target', '出血' ) < 5 and getDebuffRemainTime('target', '割裂') > 0 
end)

scheme.add('君王之灾', 'target', function()
    return getDebuffRemainTime('target', '割裂') > 0 and UnitIsPlayer('target')  
end)

scheme.add('出血', 'target', function( )
    return MaxComboPoints() - getComboPoints() == 1
end)

scheme.add('毁伤', 'target', function( )
    return MaxComboPoints() - getComboPoints() >= 2
end)


function scheme.shenji()
    if getComboPoints() > 1 then
        s.sf_then_start('肾击', 'target')
    end
end


function scheme.mengun()
    s.sf_then_stop('闷棍', 'target')
end

function scheme.zhuazei( )
    print('start find steal player')
    s.sf(function ( )
        -- if ut.commonJudge('闷棍', 'target') then
        --     ut.cast('闷棍', 'target')
        -- end
        for i=1, 3 do
            local t = 'arena' .. i
            if UnitExists(t) and ut.commonJudge('闷棍', t) and not UnitIsUnit('target', t) then
                ut.cast('闷棍', t)
                break
            end
        end
    end)

    s.on_cast_succeeded = function(caster, spell )
        if caster == 'player' and spell == '闷棍' then
            print('convert to stop')
            s.stop()
        end
    end
end

function scheme.touxi()
    s.sf_then_start('偷袭', 'target', function(t) 
        return getDebuffRemainTime('target', '偷袭') < 0.1 and not immune_coma('target')
    end)
end

function scheme.touxiOther()
    s.sf_then_start('偷袭', 'other', function(t) 
        return t and IsSpellInRange('偷袭', t) == 1 and getDebuffRemainTime(t, '偷袭') < 0.1 and not immune_coma(t) 
    end)
end

function scheme.xiaoshi()
    s.sf_then_stop('消失', nil)
end


function scheme.yanggong( )
    s.sf_then_weakStop('佯攻', nil, function() 
         return  getBuffRemianTime('player','佯攻') < 1
    end)

end

function scheme.zaoji()
    if IsAltKeyDown() then
        s.sf('凿击', 'other')
    else
        s.sf('凿击', 'target')
    end
end
function scheme.zhimang()
    if IsAltKeyDown() then
        s.sf('致盲', 'other')
    else
        s.sf('致盲', 'target')
    end
end

function scheme.chouxue( )
    s.sf(function( )
        ut.cast('抽血', 'target')
        ut.cast('出血', 'target')
    end)
end


function scheme.daduan( )
    s.sf(function()
        local usable, nomana = IsUsableSpell('脚踢')
        local start, duration, enabled = GetSpellCooldown('脚踢')
        -- print(usable, start)
        if not usable or start ~= 0 then
            return false
        end

        if interruptJudge('target') then
            ut.cast('脚踢', 'target')
            return true
        end

        for i=1, 5 do
            local t = 'arena' .. i
            if UnitExists(t) then
                if interruptJudge(t) then
                    ut.cast('脚踢',t)
                    return true
                end
            else 
                break
            end
        end
    end)
end

function scheme.dushang( )
     s.sf_then_start('毒伤', 'target')   -- body
end

function scheme.tianjiangshaji( )
    s.sf_then_start('天降杀机', 'target')
    ut.castSpells( '飞镖投掷', '剧毒之刃')
end

function scheme.feishen( )
    -- body
    s.weakStop()
    if ut.commonJudge('暗影步', 'target') and ut.commonJudge('肾击') then
        ut.cast('暗影步', 'target')

        s.on_cast_succeeded = function(caster, spell )
            if caster == 'player' and spell == '暗影步' then
                s.addNextStepCb(function ()
                    print(ObjectPosition('player'))
                    -- ut.cast('肾击', 'target')
                    s.shenji()
                end)
            end
        end
    end
end

function scheme.startcs( )
    -- body
    if not UnitExists('target') then
        return
    end
    if GetDistanceBetweenObjects('player', 'target') > 10 then
        s.sf_then_start('剧毒之刃', 'target')
    else
        s.start()
    end
end

--[[
Slots = {
    Head,
    Shoulders,
    Shirt,
    Chest,
    Waist,
    Legs,
    Feet,
    Wrists,
    Hands,
    Back,
    MainHand,
    OffHand,
    Tabard,
};
]]

-- local dispayId = 50 
-- 61056 ai sa la 
local dispayId = 15475
function scheme.isMorph( )
    return UnitGetDisplayID('player') == dispayId
end
function scheme.morph( )
    print("morph ... ")
    UnitSetDisplayID('player', dispayId)

    UnitSetItem('player', Slots.MainHand, 32837) -- dan dao
    UnitSetItem('player', Slots.OffHand, 32838)
    -- UnitSetItem('player', Slots.MainHand, 19019) -- feng jian
    -- UnitSetItem('player', Slots.OffHand, 19019)
    UnitSetItem('player', Slots.Wrists, 22483)
    UnitSetItem('player', Slots.Chest, 22476)
    UnitSetItem('player', Slots.Hands, 22481)
    UnitSetItem('player', Slots.Head, 22478)
    UnitSetItem('player', Slots.Legs, 22477)
    UnitSetItem('player', Slots.Shoulders, 22479)
    UnitSetItem('player', Slots.Feet, 22480)
    UnitSetItem('player', Slots.Waist, 22482)

    UnitUpdateModel('player')
end

registerEvent('PLAYER_ENTERING_WORLD', function( ... )
    if not scheme.isMorph() then   
        scheme.morph()
    end
end)

--[[
registerEvent('UNIT_TARGET', function( ... )
    -- print(...)
    local unit = ...
    if unit == 'player' then
        s.weakStop()
    end
end)]]

editWowMacro('佯攻', [[
#showtooltip 佯攻
/run s.yanggong()
]])

editWowMacro('凿击', [[
#showtooltip 凿击
/run s.zaoji()
]])
editWowMacro('抽血', [[
#showtooltip 抽血
/run s.chouxue()
]])
editWowMacro('毒刃', [[
#showtooltip 毒刃
/run s.sf('毒刃', 'target')
]])
editWowMacro('刀扇', [[
#showtooltip 刀扇
/run s.sf_then_start('刀扇')
]])

editWowMacro('偷袭', [[
#showtooltip 偷袭
/run s.touxi()
]])

editWowMacro('偷袭other', [[
#showtooltip 偷袭
/run s.touxiOther()
]])

editWowMacro('抓贼', [[
#showtooltip 闷棍
/run s.zhuazei()
]])
editWowMacro('锁喉', [[
#showtooltip 锁喉
/run s.sf_then_start('锁喉', 'target')
]])

editWowMacro('毒伤', [[
#showtooltip 毒伤
/run s.dushang()
]])

editWowMacro('宿敌', [[
#showtooltip 宿敌
/run s.sf_then_start('宿敌', 'target')
]])

editWowMacro('君王之灾', [[
#showtooltip 君王之灾
/run s.sf_then_start('君王之灾', 'target')
]])

editWowMacro('闷棍', [[
#showtooltip 闷棍
/run s.mengun()
]])
editWowMacro('致盲', [[
#showtooltip 致盲
/run s.zhimang()
]])

editWowMacro('肾击', [[
#showtooltip 肾击
/run s.shenji()
]])
editWowMacro('飞肾', [[
#showtooltip 暗影步
/run s.feishen()
]])

editWowMacro('天降杀机', [[
#showtooltip 天降杀机
/run s.tianjiangshaji()
]])


editWowMacro('脚踢', [[
#showtooltip 脚踢
/run s.daduan()
]])
editWowMacro('morph', [[
//#showtooltip 埃辛诺斯战刃
/run s.morph()
]])
editWowMacro('暗影斗篷', [[
#showtooltip 暗影斗篷
/run s.sf_then_weakStop('暗影斗篷')
]])

editWowMacro('startcs', [[
#showtooltip 毁伤
/run s.startcs() 
]])

--macroId = EditMacro(1, "MyMacro", 12, "/script CastSpellById(1);", 1, 1);
--macroId = EditMacro(1, "MyMacro", 12, "/script CastSpellById(1);", 1, 1);
--local macroId = CreateMacro("MyMacro", "INV_MISC_QUESTIONMARK", "/run print('hello binding')", nil)
--local ok = SetBindingMacro("CTRL-T", macroId);
return scheme